#pragma once
#include"noncopyable.h"
#include"Thread.h"

#include<functional>
#include<mutex>
#include<condition_variable>
#include<string>
// 只用到了指针，所以是前置声明
class EventLoop;
class EventLoopThread : noncopyable
{    
    public:
    using ThreadInitCallback = std::function<void(EventLoop*)>; 
    // EventLoopThread 跑着就是一个个的EventLoop事件
    EventLoopThread(const ThreadInitCallback& cb = ThreadInitCallback(),
    const std::string& name = std::string());

    ~EventLoopThread();

    EventLoop* startLoop();
    private:
    void threadFunc();

    EventLoop* loop_;       // Thread对象运行的事件
    bool exiting_;
    Thread thread_;         // 封装了一个Thread对象
    std::mutex mutex_;      // 互斥锁
    std::condition_variable cond_; // 条件变量
    ThreadInitCallback callback_;
};